import { Vector2 } from "three";

export default class NodeLink {
    node: Vector2;
    next: NodeLink;


    /**
     * 
     * @param p 从数组得来
     */
    setFromArray(p: Array<Vector2>) {
        let curr: NodeLink = this;
        let last: NodeLink = null;
        

        for (let i = 0; i < p.length ; i++) {

            if(!curr){
                curr = new NodeLink();
            }

            let item = p[i];
            curr.node = item;

            if(last){
                last.next = curr;
            }

            last = curr;
            curr = curr.next;
        }

        last.next = this;

        return this;
    }

    /**
     * 
     * @param v 设置值
     */
    setValueFromNode(v: NodeLink) {
        this.node = v.node;
    }


    /**
     * 
     * @param v 复制值
     */
    copyValueFromNode(v: NodeLink) {
        this.node = v.node ? v.node.clone() : null;
    }
}